<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl">
    <style type="text/css">
        #TravelModal img {
            width: 100%;
        }

        #TravelModal .modal-body {
            max-height: 500px;
            overflow-y: auto;
        }
    </style>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <!--设置当前要回显当前菜单,必须在载人菜单前完成设置-->
            <#assign menu="releaseTravel"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">已发布游记管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/travel/releaseList.do" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题">
                </div>
                <button type="submit" class="btn btn-success">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>标题</th>
                    <th>封面</th>
                    <th>地点</th>
                    <th>作者</th>
                    <th>发布时间</th>
                    <th>状态</th>
                    <th colspan="3">操作</th>
                </tr>
                <#list result.list as entity>
                <tr>
                    <td>${entity.title!}</td>
                    <td><img src="${entity.coverUrl!}" width="40px"/></td>
                    <td>${(entity.place.name)!}</td>
                    <td>${(entity.author.nickName)!}</td>
                    <td>${(entity.releaseTime?string("yyyy-MM-dd"))!}</td>
                    <td>${entity.stateName!}</td>
                    <td><a href="javascript:;" data-id="${entity.id}" class="showTravel">查看文章</a></td>
                    <td><a href="javascript:;" data-id="${entity.id}" data-state="2" id="reject">取消发布</a></td>
                    <td><a href="javascript:;" data-json='${entity.jsonString}' class="commened">推荐</a></td>

                </tr>
                </#list>
            </table>
           <#include "../common/page.ftl">
        </div>
    </div>
</div>

<div class="modal fade" id="TravelModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">查看游记</h4>
            </div>
            <div class="modal-body">

            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="editForm"
                      enctype="multipart/form-data">
                    <input type="hidden" name="travel.id"/>
                    <input type="hidden" name="coverUrl"/>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="title"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">副标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="subTitle" placeholder="请输入副标题"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">封面：</label>
                        <div class="col-lg-6">
                            <img id="coverUrl" style="width: 100px"/>
                            <input type="file" class="form-control" name="image"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">推荐时间：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="schedule" placeholder="请选择推荐时间"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">推荐类型：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="type">
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary saveBtn">保存</button>
            </div>
        </div>
    </div>
</div>


<script>
    $("#reject").click(function () {
        var id = $(this).data("id");
        var state = $(this).data("state");
        $.get("/travel/changeState.do", {"id": id, "state": state}, function (data) {
            if (data.success) {
                reload();
            } else {
                $.messager.alert("提示", data.msg)
            }
        }, "json");
    });

    $(".showTravel").click(function () {
        var id = $(this).data("id");
        $.get("/travel/selectOne.do", {id: id}, function (data) {
            $("#TravelModal .modal-body").html(data.content);
        }, "json")
        $("#TravelModal").modal("show");
    });

    $(".commened").click(function () {
        var json = $(this).data("json");
        console.log(json);
        if (json) {
            $("#editForm input[name=title]").val(json.title);
            $("#editForm input[name=coverUrl]").val(json.coverUrl);
            $("#editForm input[name='travel.id']").val(json.id);
            $("#coverUrl").attr("src", json.coverUrl);
        }
        $("#inputModal").modal("show");
    });

    $(".saveBtn").click(function () {
        var travelId = $("#editForm input[name='travel.id']").val();
        $.get("/travelCommend/selectForCommend.do",{"travelId":travelId},function (data) {
            if(data.success){
                $("#editForm").ajaxSubmit(function (data) {
                    console.log(data);
                    if (data.success) {
                        reload("/travelCommend/list.do");
                    } else {
                        $.message.alert("提示", data.msg);
                    }
                });
            }else{
                $.messager.alert("警告",data.msg);
            }
        });
    });

    //m97date时间控件
    $("#editForm input[name='schedule']").click(function () {
        WdatePicker({
            readOnly: true,
            maxDate: new Date()
        })
    });
</script>

</body>
</html>